// 一级界面从PopupWindow派生 ，重载onShow即可以使用。
// 一级界面可以挡住全屏幕，所以不需要跟panel的行为一样

class PopupWindow extends DockWindow {
	popupBy: string;

	bgDark: eui.Image;

	getGroup(): string {
		return '';
	}

	async close(): Promise<void> {
		this.isShow = false;
		if (this.isWindowEffect()) {
			await asyncSetEffectUI(this, 'popDown', 100);
		}
		MainWindow.ins().layerDlg.clearPopup(this, this.getGroup());
		this.onShow(false);
	}

	toggle(): void {
		if (this.stage) {
			this.close();
			return;
		}
		this.show();
	}

	show(): void {
		this.isShow = true;
		MainWindow.ins().layerDlg.popup(this, this.isWindowEffect() ? 'popUp' : '');
		this.onShow(true);
	}

	override onEsc(): void {
		this.onShow(false);
		if (this.isWindowEffect()) {
			setEffectUI(this, 'popUp', 100);
		}
	}

	onShow(_visible: boolean): void {}

	override setRightClose(): void {
		this.addEventListener(MainRightClick.rightDownEvent, this.onRightClose, this);
	}

	override onRightClose(): void {
		this.onClose();
	}

	// 设置窗口样式的全屏ui点击bgDark自动关闭界面
	setBgClickClose(): void {
		if (this.bgDark) {
			this.bgDark.addEventListener(
				'touchTap',
				this.close,
				this,
			);
		}
	}
}
